import 'package:flutter_pink_app/mock/mock_activityList.dart';
import 'package:flutter_pink_app/util.dart';
import "recommend.dart";
import '../mock/mock_AnimateList.dart';
import '../mock/mock_benefitList.dart';

// 个人中心请求数据序列化
// class ProfileSerializedGen {
//   int code;
//   ProfileData data;
//   String msg;

//   ProfileSerializedGen({this.code, this.data, this.msg});

//   ProfileSerializedGen.fromJson(Map<String, dynamic> json) {
//     code = json['code'];
//     data = json['data'] != null ? new ProfileData.fromJson(json['data']) : null;
//     msg = json['msg'];
//   }

//   Map<String, dynamic> toJson() {
//     final Map<String, dynamic> data = new Map<String, dynamic>();
//     data['code'] = this.code;
//     if (this.data != null) {
//       data['data'] = this.data.toJson();
//     }
//     data['msg'] = this.msg;
//     return data;
//   }
// }

class ProfileSerializedGen {
  String name;
  String face;
  int fans;
  int favorite;
  int like;
  int coin;
  int browsing;
  List<BannerInfo> bannerList;
  List<AnimatedInfo> animatedList;
  List<BenefitInfo> benefitList;

  ProfileSerializedGen(
      {this.name,
      this.face,
      this.fans,
      this.favorite,
      this.like,
      this.coin,
      this.browsing,
      this.bannerList,
      this.animatedList,
      this.benefitList});

  ProfileSerializedGen.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    face = json['face'];
    fans = json['fans'];
    favorite = json['favorite'];
    like = json['like'];
    coin = json['coin'];
    browsing = json['browsing'];

    /// 原
    // if (json['bannerList'] != null) {
    //   bannerList = <BannerInfo>[];
    //   json['bannerList'].forEach((v) {
    //     bannerList.add(new BannerInfo.fromJson(v));
    //   });
    // }

    /// mock
    if (json['bannerList'] != null) {
      bannerList = <BannerInfo>[];
      mockActivityist.forEach((v) {
        bannerList.add(new BannerInfo.fromJson(v));
      });
    }

    /// mock
    if (json['courseList'] != null) {
      animatedList = <AnimatedInfo>[];
      // 算一个随机数
      final randomNum = getScopeRandomInt(3, 9);
      for (int i = 0; i < randomNum; i++) {
        animatedList.add(new AnimatedInfo.fromJson(mockAnimateList[i]));
      }
      animatedList.shuffle(); // 洗牌
    }

    /// mock
    if (json['benefitList'] != null) {
      benefitList = <BenefitInfo>[];
      mockBenefitList.forEach((v) {
        benefitList.add(BenefitInfo.fromJson(v));
      });
    }
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    data['face'] = this.face;
    data['fans'] = this.fans;
    data['favorite'] = this.favorite;
    data['like'] = this.like;
    data['coin'] = this.coin;
    data['browsing'] = this.browsing;
    if (this.bannerList != null) {
      data['bannerList'] = this.bannerList.map((v) => v.toJson()).toList();
    }
    if (this.animatedList != null) {
      data['courseList'] = this.animatedList.map((v) => v.toJson()).toList();
    }
    if (this.benefitList != null) {
      data['benefitList'] = this.benefitList.map((v) => v.toJson()).toList();
    }
    return data;
  }
}

class AnimatedInfo {
  String name;
  String cover;
  String url;
  int group;

  AnimatedInfo({this.name, this.cover, this.url, this.group});

  AnimatedInfo.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    cover = json['cover'];
    url = json['url'];
    group = json['group'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    data['cover'] = this.cover;
    data['url'] = this.url;
    data['group'] = this.group;
    return data;
  }
}

class BenefitInfo {
  String name;
  String url;

  BenefitInfo({this.name, this.url});

  BenefitInfo.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    url = json['url'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    data['url'] = this.url;
    return data;
  }
}
